package com.lixin.smartclassroom.ui.home.tab5.activity

import com.drake.brv.utils.bindingAdapter
import com.drake.net.utils.scopeNet
import com.drake.net.utils.scopeNetLife
import com.lixin.smartclassroom.api.coursepinglunlist
import com.lixin.smartclassroom.bean.DataListBean
import com.lixin.smartclassroom.databinding.ActivityEventCommentBinding
import com.lixin.smartclassroom.ui.home.adapter.comment
import com.lixinkeji.base.BaseActivity
import com.lixinkeji.extension.getIntentString
import com.lixinkeji.extension.gone
import com.lixinkeji.extension.toast
import com.lixinkeji.extension.visible

/**
 * Description 活动评价
 * Author: lwc
 * Date:2023/12/11 8:57
 */
class EventCommentAct : BaseActivity<ActivityEventCommentBinding>() {
    override fun getViewBinding() = ActivityEventCommentBinding.inflate(layoutInflater)

    override fun topBarHide() = false
    override fun startPadding() = true
    override fun title() = "活动评价"
    private lateinit var listBean: ArrayList<DataListBean>
    var courseid = ""

    override fun iniView() {
        courseid = getIntentString("courseid")
        binding.recyclerComment.comment(3)

        scopeNetLife {
            val baseBean = coursepinglunlist(courseid, 1, 10)!!
            if (baseBean.result == "0") {
                if (baseBean.totalCount.isNullOrEmpty() || baseBean.totalCount == "0") {
                    binding.tvCommentCount.gone()
                    binding.divider.gone()
                } else {
                    binding.tvCommentCount.visible()
                    binding.tvCommentCount.text = "精彩评论("+baseBean.totalCount+")"
                    binding.divider.visible()
                }
            } else {
                toast(baseBean.resultNote.toString())
            }
        }

        binding.apply {
            refresh.onRefresh {
                scopeNetLife {
                    listBean = coursepinglunlist(courseid, index, 10)!!.dataList!!
                    addData(listBean) {
                        if (binding.recyclerComment.bindingAdapter.models?.size == 0) {
                            binding.state.showEmpty()
                            binding.recyclerComment.gone()
                        } else {
                            binding.recyclerComment.visible()
                        }
                        listBean.size == 10
                    }
                }
            }.autoRefresh()
        }


    }

}